package io.kiki.sba.registry.server.metadata.monitor.dataStoreNode;

import io.kiki.sba.registry.common.model.slot.DataStoreNode;
import io.kiki.sba.registry.common.model.slot.Slots;
import io.kiki.sba.registry.server.metadata.monitor.Metrics;
import io.kiki.sba.registry.server.shared.slot.SlotsRecorder;

import java.util.List;


public class DataSlotMetricsRecorder implements SlotsRecorder {
    @Override
    public void record(Slots slots) {
        List<DataStoreNode> list = slots.transfer(null, false);
        // clear the gauge
        Metrics.DataSlot.clearLeaderNumbers();
        Metrics.DataSlot.clearFollowerNumbers();
        list.forEach(dataNodeAndLeaderFollowerSlotIdSet -> {
            Metrics.DataSlot.setLeaderNumbers(dataNodeAndLeaderFollowerSlotIdSet.getDataStoreNodeId(), dataNodeAndLeaderFollowerSlotIdSet.getLeaderSlotIdSet().size());
            Metrics.DataSlot.setFollowerNumbers(dataNodeAndLeaderFollowerSlotIdSet.getDataStoreNodeId(), dataNodeAndLeaderFollowerSlotIdSet.getFollowerSlotIdSet().size());
        });
    }
}
